﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ScrumDashboard.Library.Data;
using System.Xml.Linq;

namespace ScrumDashboardMvc.Controllers
{
    [HandleError, Authorize]
    public class SprintController : Controller
    {
         IRepository _repo;

           public SprintController()
            : this(RepositoryFactory.GetRespository())
        {
        }
           public SprintController(IRepository repo)
        {
            _repo = repo;
        }

        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Save()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Releases(string project, string term)
        {
            IProjectHandler p = _repo.GetHandler<IProjectHandler>();
            XElement x = p.GetIterations(project);
            return Json((from e in x.Elements("Node").Elements("Children").Elements("Node") select e.Attribute(XName.Get("Name")).Value).ToList());
        }

        

    }
}
